﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceProcess;

namespace SPVisualDevWinSvc
{
    public partial class ServiceAccountInput : Form
    {
        public ServiceAccountInput()
        {
            InitializeComponent();

            //this.txtUserName.KeyPress += new KeyPressEventHandler(textBox_KeyPress);
            this.txtPassword1.KeyPress += new KeyPressEventHandler(textBox_KeyPress);
            this.txtPassword2.KeyPress += new KeyPressEventHandler(textBox_KeyPress);

            this.Load += new EventHandler(ServiceAccountInput_Load);
        }

        void ServiceAccountInput_Load(object sender, EventArgs e)
        {
            this.Activate();
            this.BringToFront();
        }

        void textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\n' || e.KeyChar == '\r')
            {
                if (ValidatePassword())
                {
                    this.DialogResult = DialogResult.OK;
                    this.Hide();
                }
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (ValidatePassword())
            {
                this.DialogResult = DialogResult.OK;
                this.Hide();
            }
        }

        private bool ValidatePassword()
        {
            if (this.txtPassword1.Text != this.txtPassword2.Text)
            {
                MessageBox.Show("Password missmatch.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
